package com.google.code.jbauble.mvc;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class Controller {
	protected final Logger log = LoggerFactory.getLogger(this.getClass());
	
	protected Result render(String view, Object data) {
		Result r = new Result();
		r.setType(Result.RENDER);
		r.setUrl(view);
		r.setParameters(data);
		return r;
	}
	
	protected Result render(Object data) {
		return render(null, data);
	}
	
	protected Result render() {
		return render(null, null);
	}
	
	protected Result redirect(String action) {
		Result r = new Result();
		r.setType(Result.REDIRECT);
		r.setUrl(action);
		return r;
	}
	
	protected Result forward(String action) {
		Result r = new Result();
		r.setType(Result.FORWARD);
		r.setUrl(action);
		return r;
	}
	
	protected Result output(String out) {
		Result r = new Result();
		r.setType(Result.OUTPUT);
		r.setParameters(out);
		return r;
	}
	
	protected Map getModel() {
		return new HashMap();
	}
	
	protected Object getBean(String name) {
		return WebContext.getInstance().getBean(name);
	}
}
